package com.wsc.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wsc.entity.ReadRoom;
import com.wsc.service.ReadRoomService;

@RequestMapping("/readroom")
@RestController
@CrossOrigin
public class ReadRoomController {

	@Autowired
	private ReadRoomService rs;

	// 增
	@RequestMapping("add")
	public Integer add(ReadRoom r) {
		return rs.add(r);
	}

	// 单删
	@RequestMapping("deleteById")
	public Integer deleteById(Integer id) {
		return rs.deleteById(id);
	}

	// 多删
	@RequestMapping("deleteByIds")
	public Integer deleteByIds(String ids) {
		String[] arr = ids.split(",");
		Integer flag = 0;
		for (int i = 0; i < arr.length; i++) {
			Integer id = Integer.valueOf(arr[i]);
			flag = rs.deleteById(id);
		}
		return flag;
	}

	// 改
	@RequestMapping("update")
	public Integer update(ReadRoom r) {
		return rs.update(r);
	}

	// 查 多条件 分页
	@RequestMapping("getAll")
	public Map<String, Object> getAll(String name, Integer page, Integer limit) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("name", name);
		limit = limit == null ? 10 : limit;
		page = page == null ? 0 : page - 1;
		params.put("limit", limit);
		params.put("page", page);
		return rs.getAll(params);
	}

}
